<html>
<head>
<title>CSE5317/4305 Project #4</title>
</head>
<body BGCOLOR="#FFFFFF" TEXT="#000000">
<center>
<h1>CSE5317/4305 Project #4 (Type Checking)</h1>
Due Thursday April 9 at 11:59pm<p>
Worth 18% of your project grade
</center>
<p>
<hr>
<p>
For this project, you are asked to implement the type checking program for PCAT.
You will work in the same directory <tt>pcat</tt> you used in project #3.
<p>
You will use the SymbolTable class given in System.jar.
The bindings in the Symbol Table,
when printed with the method <tt>toString()</tt>, should follow the following syntax:
<ul>
<li> <tt>VarDec(type,level,offset)</tt> : holds the type of a variable declaration.
<li> <tt>TypeDec(type)</tt> : defines a named type.
<li> <tt>ProcDec(type,label,level,min_offset,param1,...,paramn)</tt> :
the signature of a function/procedure. The first type
is the output type (<tt>NoType()</tt> for procedures) and a <tt>param</tt>
is a formal parameter, which, when printed, looks like
<tt>Param(ID,type)</tt>, that is, each formal parameter has a name and a type.
</ul>
The values of <tt>level, offset, label, min_offset</tt> should be set to 0 now,
but they will be set to their proper values in the next project.
<p>
For this project, you need to modify the file <a href="pcat/TypeCheck.gen">TypeCheck.gen</a> only.
The typecheck function typechecks <tt>e</tt>, which can be any expression, statement, declaration, etc.
If it is an expression, it returns the type of the expression (otherwise it returns the AST type <tt>NoTyp()</tt>).
The method <tt>typecheck</tt> uses the function:
<pre>
static boolean type_equivalence ( Ast tp1, Ast tp2 )
</pre>
to test whether the types
<tt>tp1</tt> and <tt>tp2</tt> are equal (recall that PCAT supports name equivalence only).
<p>
Note that, in contrast to the PCAT manual, you should not allow mixed-typed operations (eg, adding an integer
to a float). Also the for-loop introduces a new declaration: the for-variable that has an integer type.
The scope of the variable is the body of the for-loop. The variable can only be used within the body.
So ignore the PCAT manual that says that the for-variable must be declared before the for-loop.
<p>
You need to run your parser against all <tt>tests/*.pcat</tt> files.
For example:
<pre>
run 4 hello
</pre>
The output consists of the tracing of the type checker.
To test for type errors, you need to change the test files a little bit (by changing
a variable name, adding an extra argument to a call, etc), so you can get type errors.
You also need to compare your output with that of the solution:
<pre>
solution 4 hello
</pre>
<p>
After ensuring that your program compiles and executes correctly,
cleanup your <tt>pcat</tt> directory using
<tt>
clean
</tt>
Then, if you are using Linux, archive your file using <tt>tar cvf pcat.tar pcat</tt>.
If you are using Windows, zip the whole directory into the file <tt>pcat.zip</tt>.
Then submit your file (<tt>pcat.tar</tt> or <tt>pcat.zip</tt>) here:
<p>
<form enctype="multipart/form-data" action="https://lambda.uta.edu/cgi-bin/php/handin.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <input type="hidden" name="class" value="cse5317" />
    <input type="hidden" name="assignment" value="proj4" />
Submit this file: <input name="userfile" type="file" size="50"/><br/>
    <input type="submit" value="Send File" />
</form>
<p>
<hr>
<P>
<ADDRESS>Last modified: 01/14/09 by <A HREF="http://lambda.uta.edu/">Leonidas Fegaras</A></ADDRESS>
